package cn.biplam.front.component.view.systemManage.sysprivi.privilege.menu.manage;

import cn.biplam.common.ajxcode.SystemCode.MenuCode;
import cn.biplam.common.client.DataFilter;
import cn.biplam.common.client.Operator;
import cn.biplam.common.client.OperatorResult;
import cn.biplam.common.opcode.SysManageCode.MenuOptCode;
import cn.biplam.common.paramters.TreeParam;
import cn.biplam.common.struc.SysStruc.MenuStruc;
import cn.biplam.common.tools.TOOLS;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.KvMap;
import cn.biplam.common.wrapper.UserInfo;
import cn.biplam.front.component.ComponentBase;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.template.control.FlatTable;
import cn.biplam.front.template.pageFrame.mdManage.MdObject;

/**
 *  菜单信息主页面
 * @author XiaoRuxing Dec 15, 200911:27:14 AM
 * @version 1.0
 */
public class MenuMain extends ComponentBase{
	
	private static String cId = MenuCode.Menu_Info;

	public MenuMain(UserInfo user, String homeUrl, String recordId,
			KvMap<String, String> params) {
		super(user, homeUrl, recordId, params);
	}

	/**
	 *  获取菜单信息
	 * @return 菜单信息主界面
	 * @throws ErrorMessage 
	 */
	public HtmlWindow get() throws ErrorMessage{
		String recordId = params.getByKey(TreeParam.NODE_ID);
		String mainId = cId+".menu";
		MdObject mdo = new MdObject(mainId,recordId);
		mdo.putTable(getInfo(recordId, mainId+"list", "500"));
		
		HtmlWindow win = mdo.get();
		return win;
	}
	
	/**
	 * @return 菜单信息界面
	 */
	private HtmlWindow getInfo(String recordId,
			String pageId,String width) throws ErrorMessage{
		FlatTable editComp = new FlatTable(pageId, recordId);
		String name = null;
		String desc = null;
		String path = null;
		String action = null;
		OperatorResult menuInfo = Operator.get(MenuOptCode.Query_By_ID, mUser.getUserID(), 
				new DataFilter(recordId));
		if(TOOLS.exist(menuInfo)){
			name = menuInfo.getValue(MenuStruc.MENU_NAME);
			desc = menuInfo.getValue(MenuStruc.MENU_DESC);
			path = menuInfo.getValue(MenuStruc.PIC_PATH);
			action = menuInfo.getValue(MenuStruc.ACTION_ID);
		}
		//放入菜单信息
		editComp.putTh("名称", 0, 0);
		editComp.putTd(name, 0, 1);
		editComp.putTh("说明", 1, 0);
		editComp.putTd(desc, 1, 1);
		editComp.putTh("图标路径", 2, 0);
		editComp.putTd(path, 2, 1);
		editComp.putTh("跳转动作ID", 3, 0);
		editComp.putTd(action, 3, 1);
		//设置检查项
		editComp.setColSize(3, 0, 12);
		editComp.setWidth(width);
		return editComp.get();
	}
}
